﻿@using Century.Model
@model DailyAnalysis
@{
    Layout = null;
    var options = new AjaxOptions()
    {
        Url = Url.Action("DailyAnalysis", "SiteManagement"),
        UpdateTargetId = "Result",
        OnSuccess = "OnSuccessAnalysis",
        OnFailure = "OnFailureAnalysis",
        OnComplete = "OnCompleteAnalysis"
    };
}
@Html.Partial("_MessageBox")
 @section scripts{
<script type="text/javascript">
    $(document).ready(function () {
        $('#PostIT').click(function () {
            $(this).parents('form').submit();
            return false;
        });

        $('#btnCancel').click(function () {
            $('#btnAdd').show();
            $('#btnSave').hide();
            $('#btnCancel').hide();
            $('#Id').val('');
            return false;
        });
    });

    function OnSuccessAnalysis(data) {
        ReloadTree();
        OpenPopup('Message', 'Site data successfully saved.', false);
        $('#DailyReview').data('tEditor').value(data.DailyReview);
    }

    function OnFailureAnalysis(data) {
        OpenPopup('Message', 'An error occured during save operation. <br/>Please try again or contact with administrator.', true);
    }

    function OnCompleteAnalysis(data) {
        // code here
    }

    function editEnrty(id) {
        $(function () {
            $.ajax({
                url: '@(Url.Action("DailyAnalysisEdit", "SiteManagement"))',
                data: { id: id },
                type: "POST",
                datatype: "json",
                success: function (data) {
                    if (data.Success || data.Success == null) {
                        $("#Product").val(data.Product);
                        $("#PotentialDirection").val(data.PotentialDirection);
                        $("#Target").val(data.Target);
                        $("#SupportVal").val(data.SupportVal);
                        $("#Resistance").val(data.Resistance);
                        $("#ExpiryTime").val(data.ExpiryTime);
                        $("#KeyLevel").val(data.KeyLevel);
                        $("#AlternativeScenario").val(data.AlternativeScenario);
                        $("#Note").val(data.Note);
                        $("#Id").val(data.Id);
                        $('#DailyReview').data('tEditor').value(data.DailyReview);
                        $("#btnAdd").hide();
                        $("#btnSave").show();
                        $("#btnCancel").show();
                    } else {
                        OpenPopup('Message', 'An error occured during edit operation. <br/>Please try again or contact with administrator.', true);
                    }
                }
            });
        });

        return false;
    }

    function reloadList() {
        $.get('@(Url.Action("DailyAnalysisList", "SiteManagement"))', function (data) {
            $("#analysisList").html(data);
        });
    }

    function deleteEnrty(id) {
        $.get('@(Url.Action("DailyAnalysisDelete", "SiteManagement"))' + '/' + id, function (data) {
            reloadList();
        });
    }

    function setDailyAnalysisDate() {
        $.get('@(Url.Action("SetCurrentDailyAnalysisDate", "SiteManagement"))' + '/' + $("#olderAnalysis").val(), function (data) {
            reloadList();
        });
    }
</script>
     }
@{Html.EnableClientValidation();}

<div style="text-align: left; min-height: 600px; margin-bottom: 20px;" id="Result">
    @using (Ajax.BeginForm(options))
    {
        <table border="0" cellspacing="0" cellpadding="0" class="advanced-tbl">
            <tr>
                <td colspan="6">
                    <h2>Daily Analysis</h2>
                    <br />
                    <img src="@Url.Content("~/Content/themes/admin/img/general/warning.png")" alt="Warning" />
                    Please don't change if you are not sure !<br />
                    <img src="@Url.Content("~/Content/themes/admin/img/general/warning.png")" alt="Warning" />
                    Your changes will be appear on <b>Live</b>. There is no draft or etc. version for
                    these properties.<br />
                    <img src="@Url.Content("~/Content/themes/admin/img/general/warning.png")" alt="Warning" />
                    You can only delete today's analysis entiries.
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td colspan="6">
                                <b>Daily Analysis Form</b>
                                <input type="hidden" id="Id" name="Id" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Product</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.Product, new { style = "width: 70px" })
                            </td>
                            <td>
                                <b>PotentialDirection</b>
                            </td>
                            <td>
                                @Html.DropDownListFor(model => model.PotentialDirection, (SelectList)ViewBag.PotentialDirection, "", new { style = "width: 75px" })
                                @Html.ValidationMessageFor(model => model.PotentialDirection)
                            </td>
                            <td>
                                <b>Target</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.Target, new { style = "width: 70px" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Support</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.SupportVal, new { style = "width: 70px" })
                            </td>
                            <td>
                                <b>Resistance</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.Resistance, new { style = "width: 70px" })
                            </td>
                            <td>
                                <b>Expiry</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.ExpiryTime, new { style = "width: 70px" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>KeyLevel</b>
                            </td>
                            <td>
                                @Html.TextBoxFor(model => model.KeyLevel, new { style = "width: 70px" })
                            </td>
                            <td>
                                <b>Alternative</b>
                            </td>
                            <td>
                                @Html.TextAreaFor(model => model.AlternativeScenario)
                            </td>
                            <td>
                                <b>Note</b>
                            </td>
                            <td>
                                @Html.TextAreaFor(model => model.Note)
                            </td>
                        </tr>
                        <tr>
                            <td style="vertical-align: top;">
                                <b>Daily Review</b>
                            </td>
                            <td colspan="5">
                                @(Html.Telerik().Editor().Name("DailyReview")
                                   .Encode(false)
                                   .FileBrowser(t => t.Browse("Browse", "ImageBrowser", new { area = "Admin" })
                                   )
                                   .HtmlAttributes(new { style = "width: 100%; height: 250px;" })
                                   .Value(
                                   (Model != null ? Server.HtmlDecode(Model.DailyReview) : string.Empty)
                                     )
                                )
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Upload Analysis Image(s)</b>
                            </td>
                            <td colspan="6">
                                @(Html.Telerik().Upload()
                                        .Name("attachments")
                                        .ShowFileList(true)
                                        .Multiple(false)
                                        .Async(async => async
                                        .Save("DailyAnalysisFileUpload", "SiteManagement")
                                        .Remove("DailyAnalysisFileRemove", "SiteManagement")
                                        .AutoUpload(false)
                                 ))
                            </td>
                        </tr>
                        <tr style="height: 50px;">
                            <td align="left" nowrap="nowrap">
                                <input type="submit" class="btn_green btn" value="Add" id="btnAdd" />
                                <input type="submit" class="btn_green btn" value="Save" id="btnSave" style="display:none"/>
                            </td>
                            <td colspan="5" align="left" nowrap="nowrap">
                                <input type="button" class="btn_green btn" value="Cancel" id="btnCancel" style="display:none"/>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td colspan="6" id="analysisList">
                                @Html.Action("DailyAnalysisList", "SiteManagement", new { area = "Admin" })
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
    }
</div>
